package com.ks.user.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ks.core.base.OperationContext;
import com.ks.core.constant.Const;
import com.ks.core.constant.DatePanel;
import com.ks.user.entity.MemberVisit;
import com.ks.user.dao.MemberVisitMapper;
import com.ks.user.service.IMemberVisitService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * <p>
 * 表结构公共字段 服务实现类
 * </p>
 *
 * @author kingdee123
 * @since 2021-04-30
 */
@Service
public class MemberVisitServiceImpl extends ServiceImpl<MemberVisitMapper, MemberVisit> implements IMemberVisitService {
    @Resource
    private MemberVisitMapper memberVisitMapper;

    @Override
    public int addMemberVisit(String appId, String openId, int tenantID) {
        MemberVisit visit = new MemberVisit();
        visit.setAppId(appId);
        visit.setOpenId(openId);
        visit.setTenantID(tenantID);
        Integer insert = memberVisitMapper.insert(visit);
        return insert;
    }

    @Override
    public Map<String, Object> getMemberVisitCount(OperationContext context) {
        Map<String, Object> map = new HashMap<>();
        EntityWrapper<MemberVisit> wrapper =new EntityWrapper<>();
        MemberVisit visit =new MemberVisit();
        visit.setDelMark(Const.DEL_FLAG_NORMAL);
        visit.setTenantID(context.getTenantId().intValue());
        wrapper.setEntity(visit);
        Integer integer = memberVisitMapper.selectCount(wrapper);
        map.put("CardName", "小程序累计访问量");
        map.put("DataCount", "1");
        List list = new ArrayList();
        DatePanel panel = new DatePanel();
        panel.setDataTime(new Date());
        panel.setDataValue(integer);
        panel.setValueType("STR");
        list.add(panel);
        map.put("date", list);
        return map;
    }
}
